﻿import QtQuick 2.12
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.12
import QtGraphicalEffects 1.0
import QRCode 1.0
Item {
    id: root
    anchors.fill: parent
    visible:false
    property real itemWidth: 200
    property real itemHeight: 200
    property string filelink:""

    Rectangle {
        id: background
        anchors.fill: parent
        color: "#BDBDBD"
        opacity: 0.5
    }

    MouseArea{
        anchors.fill: parent
        onClicked: {
            hide()
        }
    }

    Rectangle{
        id:contentitem
        width: itemWidth
        height: itemHeight
        radius: 3
        anchors.centerIn: parent
        QtQuick2QREncode{
            id:qr
            anchors.fill: parent
            anchors.margins: 10
            qrSize: Qt.size(width,width)
            anchors.centerIn: parent
            qrData:filelink
            qrForeground: "black"
            qrBackground: "white"
            qrMargin: 0
            qrMode:QtQuick2QREncode.MODE_8
            qrLevel:QtQuick2QREncode.LEVEL_H
            qrLogo:"qrc:/user_kong.png"
        }
        MouseArea {
            anchors.fill: parent
            acceptedButtons: Qt.LeftButton
            property point clickPos: "0,0"

            onPressed: {
                clickPos  = Qt.point(mouse.x,mouse.y)
                //console.log("mouse Pressed")
            }
            onPositionChanged: {
                var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
                window.setX(window.x+delta.x)
                window.setY(window.y+delta.y)
            }
            onReleased: {
                var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
                window.setX(window.x+delta.x)
                window.setY(window.y+delta.y)
            }
        }
    }
    RectangularGlow {
        z: -1
        anchors.fill: contentitem
        glowRadius: 6
        spread: 0.22
        color: "#20000000"
    }
    function show() {
        qr.update()
        root.visible = true;
    }

    function hide() {
        root.visible = false;
    }
}
